home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / citsrc6K05.lha / msgout.c < prev    next >
C/C++ Source or Header  |  1996-10-29  |  21KB  |  901 lines

  1. /*
  2. *                               msgout.c
  3. *
  4. * External Message writer.  For use with external OtherNet parsers.
  5. */
  6. /*
  7. *                               history
  8. *
  9. * 92Jan17 HAW  1.4 - Hard-wire room name to msgs; handle domain field.
  10. * 91Mar26 HAW  1.3 - Virtual rooms.
  11. * 89Sep25 HAW  1.2 - update for Route Mail.
  12. * 88Nov17 HAW  Created.
  13. */
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include "ctdl.h"
  17. #include "2ndfmt.h"
  18. #include "stdarg.h"
  19. #include "dos.h"
  20. #include "math.h"
  21. /*
  22. *                               contents
  23. *
  24. */
  25. #define TITLE           "C86Net Message Exporter "
  26. #define NO_ERROR        0
  27. #define BAD_ARGS        1
  28. #define BAD_TABLE       2
  29. #define NO_NODE         3
  30. #define FATAL           4
  31. #define BAD_OUT_FILE    5
  32. #define LF_ERROR        6
  33.  
  34. char onConsole=1, remoteSysop;
  35.  
  36. FILE            *outfile;
  37. extern FILE *upfd;
  38. extern CONFIG      cfg;                 /* Configuration variables      */
  39. extern MessageBuffer msgBuf;    /* The -sole- message buffer    */
  40. extern aRoom       roomBuf;             /* Room buffer */
  41. extern logBuffer   logBuf;
  42. extern FILE        *roomfl, *logfl;
  43. extern int         thisRoom;    /* Current room    */
  44. extern rTable      *roomTab;
  45. extern struct mBuf mFile1, mFile2;
  46. extern SListBase Serves;
  47. extern NetTable    *netTab;
  48. extern NetBuffer   netBuf, netTemp;
  49. extern FILE        *netfl;
  50. extern LogTable    *logTab;
  51. extern FILE        *msgfl, *msgfl2;
  52. FILE       *GlobalFd, *netMisc;
  53. static int RCount, SCount;
  54. extern int         thisNet;        /* Current node in use          */
  55. char *R_SH_MARK =  "&&";
  56. char *NON_LOC_NET= "%%";
  57. char *LOC_NET =    "++";
  58. char inNet = ANYTIME_NET;
  59. #ifdef ANSI_PROTOTYPING
  60. void NetField(char field, char *value);
  61. void MsgOutGenInit(void);
  62. void MODoVirtuals(void);
  63. void Process(void);
  64. int  FindNet(label nm);
  65. int ThrowAll(int which, char *distance, MSG_NUMBER start, MSG_NUMBER end,
  66. char *room);
  67. void UtilRoomSend(int rover, char *send1, char *send2, char *send3);
  68. void HandleMessage(char *addr1, char *addr2, char *addr3);
  69. int  RoutePath(char *rp, char *str);
  70. char FindMessage(SECTOR_ID loc, MSG_NUMBER id);
  71. void NetFormat(void);
  72. void NowRouteMail(void);
  73. void MoutCC();
  74. void MoutForeign();
  75. int ReadRoutedDest(int c);
  76. int ReadRouted(void);
  77. #endif
  78. void Intel32ToMotorola(UNS_32 *);
  79.  
  80. int  mPrintf(char *format, ...) {return 0; }  /* stub to quiet the linker */
  81.  
  82.  
  83. /*
  84. * crashout()
  85. *
  86. * Crash exit handler.
  87. */
  88. void crashout(str)
  89. char *str;
  90.   {
  91.   printf(str);
  92.   writeSysTab();
  93.   exit(FATAL);
  94.  
  95.   }
  96. /*
  97. * main()
  98. *
  99. * Main manager
  100. */
  101. int  main(int, char **);
  102. int  main(argc, argv)
  103. char **argv;
  104. int  argc;
  105.   {
  106.   int rover;
  107.   extern char *WRITE_ANY;
  108.   printf("%s %s\n%s\n\n", TITLE, VERSION_NAME, COPYRIGHT);
  109.   /* not enough arguments?  Explain. */
  110.   if (argc < 3)
  111.     {
  112.     printf("usage: MSGOUT nodename file\n");
  113.     exit(BAD_ARGS);
  114.  
  115.     }
  116.   cfg.weAre = UTILITY;
  117.   if (!readSysTab(TRUE, TRUE))
  118.     {
  119.     exit(BAD_TABLE);
  120.  
  121.     }
  122.   if (access(LOCKFILE, 0) != ERROR)
  123.     {
  124.     printf("Please do not run MsgOut using Outside Commands.\n");
  125.     exit(LF_ERROR);
  126.  
  127.     }
  128.   MsgOutGenInit();
  129.   VirtInit();
  130.   if (FindNet(argv[1]) == ERROR)
  131.     {
  132.     writeSysTab();
  133.     printf("Could not find node %s.\n", argv[1]);
  134.     exit(NO_NODE);
  135.  
  136.     }
  137.   if ((outfile = fopen(argv[2], WRITE_ANY)) == NULL)
  138.     {
  139.     writeSysTab();
  140.     printf("Couldn't open output file %s.\n", argv[2]);
  141.     exit(BAD_OUT_FILE);
  142.  
  143.     }
  144.   Process();
  145.   putNet(thisNet, &netBuf);
  146.   writeSysTab();
  147.   return 0;
  148.   }
  149. /*
  150. * MsgOutGenInit()
  151. *
  152. * This handles general initialization.
  153. */
  154. void MsgOutGenInit()
  155.   {
  156.   SYS_FILE fn;
  157.   initNetBuf(&netBuf);
  158.   initNetBuf(&netTemp);
  159.   makeSysName(fn, "ctdlnet.sys", &cfg.netArea);
  160.   openFile(fn, &netfl);
  161.   initRoomBuf(&roomBuf);
  162.   makeSysName(fn, "ctdlroom.sys", &cfg.roomArea);
  163.   openFile(fn, &roomfl);
  164.   InitMsgBase();
  165.  
  166.   }
  167. /*
  168. * Process()
  169. *
  170. * This is the main processor.
  171. */
  172. void Process()
  173.   {
  174.   char          *send1, *send2, *send3;
  175.   label         temp;
  176.   SYS_FILE              fn;
  177.   FILE          *mail;
  178.   int                   rover;
  179.   extern char           *READ_ANY;
  180.   struct netMLstruct    buf;
  181.   /* first we handle Mail>. */
  182.   if (netBuf.nbflags.normal_mail)
  183.     {
  184.     sPrintf(temp, "%d.ml", thisNet);
  185.     makeSysName(fn, temp, &cfg.netArea);
  186.     if ((mail = fopen(fn, READ_ANY)) == NULL)
  187.       {
  188.       printf("WARNING: Couldn't open %s for mail delivery to %s.\n",
  189.       fn, netBuf.netName);
  190.  
  191.       }
  192.     else
  193.       {
  194.       while (getMLNet(mail, buf))
  195.       if (FindMessage(buf.ML_loc, buf.ML_id))
  196.         {
  197.         strCpy(msgBuf.mbroom, "Mail");
  198.         NetFormat();
  199.  
  200.         }
  201.       fclose(mail);
  202.       unlink(fn);               /* kill mail file */
  203.  
  204.       }
  205.     netBuf.nbflags.normal_mail = FALSE;
  206.  
  207.     }
  208.   NowRouteMail();               /* now handle any route mail */
  209.   /* now we handle the shared rooms */
  210.   for (rover = 0; rover < SHARED_ROOMS; rover++)
  211.     {
  212.     /* if we share this room, check for new msgs. */
  213.     if (isSharedRoom(thisNet, rover) && roomValidate(thisNet, rover))
  214.       {
  215.       getRoom(netRoomSlot(rover));
  216.       send1 = R_SH_MARK;
  217.       send2 = send3 = "guh";
  218.       switch (roomBuf.rbShareType)
  219.         {
  220.         case REG_HOST:
  221.         printf("WARNING: Please do not use Regional Host settings.\n");
  222.         printf("\nThey are obsolete.\n");
  223.         case PEON:
  224.         break;
  225.         case BACKBONE:
  226.         switch (netBuf.netRooms[rover].mode)
  227.           {
  228.           case PEON:
  229.           send2  = NON_LOC_NET;
  230.           break;
  231.           case ACTIVE_BACKBONE:
  232.           case PASS_BACKBONE:
  233.           case REG_HOST:
  234.           send2 = NON_LOC_NET;
  235.           send3 = LOC_NET;
  236.           break;
  237.           default: crashout("shared rooms: #2");
  238.  
  239.           }
  240.         break;
  241.         default: crashout("shared rooms: #1");
  242.  
  243.         }
  244.       UtilRoomSend(rover, send1, send2, send3);
  245.  
  246.       }
  247.  
  248.     }
  249.   MODoVirtuals();
  250.   UpdVirtStuff();
  251.  
  252.   }
  253. /*
  254. * UtilRoomSend()
  255. *
  256. * Send stuff out.
  257. */
  258. void UtilRoomSend(rover, send1, send2, send3)
  259. int rover;
  260. char *send1, *send2, *send3;
  261.   {
  262.   int i;
  263.   for (i = 0; i < MSGSPERRM; i++)
  264.     {
  265.     if (roomBuf.msg[i].rbmsgNo > netBuf.netRooms[rover].lastMess)
  266.       {
  267.       if (FindMessage(roomBuf.msg[i].rbmsgLoc, roomBuf.msg[i].rbmsgNo))
  268.         {
  269.         strcpy(msgBuf.mbroom, roomBuf.rbname);
  270.         HandleMessage(send1, send2, send3);
  271.  
  272.         }
  273.  
  274.       }
  275.  
  276.     }
  277.   netBuf.netRooms[rover].lastMess = roomTab[thisRoom].rtlastMessage;
  278.   netTab[thisNet].netTRooms[rover].lastMess =
  279.   roomTab[thisRoom].rtlastMessage;
  280.  
  281.   }
  282. /*
  283. * HandleMessage()
  284. *
  285. * This decides if a message should be sent out.
  286. */
  287. void HandleMessage(addr1, addr2, addr3)
  288. char *addr1, *addr2, *addr3;
  289.   {
  290.   if ((strncmp(msgBuf.mbaddr, addr1, strLen(addr1)) == SAMESTRING  ||
  291.   strncmp(msgBuf.mbaddr, addr2, strLen(addr2))      == SAMESTRING  ||
  292.   strncmp(msgBuf.mbaddr, addr3, strLen(addr3))      == SAMESTRING) &&
  293.   RoutePath(LOC_NET, msgBuf.mbaddr)     != thisNet &&
  294.   RoutePath(NON_LOC_NET, msgBuf.mbaddr) != thisNet)
  295.     {
  296.     NetFormat();
  297.  
  298.     }
  299.  
  300.   }
  301. /*
  302. * RoutePath()
  303. *
  304. * This function returns the number of the node that routed this msg
  305. * to here.  If the msg was not routed in from a BackBone, then
  306. * return ERROR, which will never match another node's #.
  307. * 88Oct13: Now simply check for msg origin, assume if one exists
  308. * that it should be checked.  Don't remember why it is restricted
  309. * to only BACKBONE-routed msgs.  Doesn't seem necessary.
  310. */
  311. int RoutePath(rp, str)
  312. char *str, *rp;
  313.   {
  314.   if (strncmp(rp, str, strLen(rp)) == SAMESTRING)
  315.     {
  316.     if (strLen(str) != strLen(rp)) /* prevent return of 0 */
  317.     return atoi(str + 2);
  318.  
  319.     }
  320.   return ERROR;
  321.  
  322.   }
  323. /*
  324. * FindNet()
  325. *
  326. * This function will find the named node.  Stolen from searchNameNet/NETMISC.
  327. */
  328. int  FindNet(nm)
  329. label nm;
  330.   {
  331.   int rover;
  332.   for (rover = 0; rover < cfg.netSize; rover++)
  333.     {
  334.     if (netTab[rover].ntflags.in_use &&
  335.     hash(nm) == netTab[rover].ntnmhash)
  336.       {
  337.       getNet(rover, &netBuf);
  338.       if (strCmpU(netBuf.netName, nm) == SAMESTRING)
  339.       return rover;
  340.  
  341.       }
  342.  
  343.     }
  344.   return ERROR;
  345.  
  346.   }
  347. /*********** These functions stolen & modified from MSG.C ***************/
  348. /*
  349. * FindMessage()
  350. *
  351. * This gets all set up to do something with a message.  We use this rather
  352. * than the findMessage in libmsg.c so we can automatically read in the 'M'
  353. * field.
  354. */
  355. char FindMessage(loc, id)
  356. SECTOR_ID  loc;         /* sector in message.buf */
  357. MSG_NUMBER id;          /* unique-for-some-time ID# */
  358.   {
  359.   MSG_NUMBER here;
  360.   startAt(msgfl, &mFile1, loc, 0);
  361.   do
  362.     {
  363.     getMessage(getMsgChar, FALSE, TRUE, TRUE);
  364.     here = atol(msgBuf.mbId);
  365.  
  366.     }
  367.   while (here != id &&  mFile1.thisSector == loc);
  368.   return (char) ((here == id));
  369.  
  370.   }
  371. /*
  372. * NetFormat()
  373. *
  374. * This function writes a message to disk.
  375. */
  376. void NetFormat()
  377.   {
  378.   MSG_NUMBER val;
  379.   if (!msgBuf.mborig[0])
  380.   strCpy(msgBuf.mborig, cfg.nodeId + cfg.codeBuf);
  381.   if (!msgBuf.mboname[0])
  382.   strCpy(msgBuf.mboname, cfg.nodeName + cfg.codeBuf);
  383.   if (!msgBuf.mbsrcId[0])
  384.     {
  385.     val = atol(msgBuf.mbId);
  386.     sPrintf(msgBuf.mbsrcId, "%ld %ld",
  387.     (val & 0xffff0000) >> 16, val & 0xffffl);
  388.  
  389.     }
  390.   if (msgBuf.mbauth[0])   NetField('A', msgBuf.mbauth);
  391.   if (msgBuf.mbdate[0])   NetField('D', msgBuf.mbdate);
  392.   if (msgBuf.mbtime[0])   NetField('C', msgBuf.mbtime);
  393.   if (msgBuf.mboname[0])  NetField('N', msgBuf.mboname);
  394.   if (msgBuf.mbdomain[0]) NetField('X', msgBuf.mbdomain);
  395.   if (msgBuf.mborig[0])   NetField('O', msgBuf.mborig);
  396.   if (msgBuf.mbroom[0])   NetField('R', msgBuf.mbroom);
  397.   if (msgBuf.mbsrcId[0])  NetField('S', msgBuf.mbsrcId);
  398.   if (msgBuf.mbto[0])     NetField('T', msgBuf.mbto);
  399.   if (msgBuf.mbOther[0])  NetField('P', msgBuf.mbOther);
  400.   RunList(&msgBuf.mbCC, MoutCC);
  401.   RunList(&msgBuf.mbForeign, MoutForeign);
  402.   NetField('M', msgBuf.mbtext);
  403.  
  404.   }
  405. /*
  406. * NetField()
  407. *
  408. * Work function to write out a field and its identifier.
  409. */
  410. void NetField(field, value)
  411. char *value, field;
  412.   {
  413.   fprintf(outfile, "%c%s", field, value);
  414.   putc(0, outfile);
  415.  
  416.   }
  417. /*
  418. * MoutCC()
  419. *
  420. * This handles the CC field of a message.
  421. */
  422. void MoutCC(dd)
  423. char *dd;
  424.   {
  425.   NetField('W', dd);
  426.  
  427.   }
  428. /*
  429. * MoutForeign()
  430. *
  431. * This handles the Foreign fields of a message.
  432. */
  433. void MoutForeign(dd)
  434. char *dd;
  435.   {
  436.   NetField(dd[0], dd + 1);
  437.  
  438.   }
  439. static int  RWorkBuf[7];
  440. /*
  441. * NowRouteMail()
  442. *
  443. * This function handles outgoing route mail.
  444. */
  445. void NowRouteMail()
  446.   {
  447.   int           rover;
  448.   label temp;
  449.   SYS_FILE      fn;
  450.   extern char *READ_ANY, OverRides;
  451.   if (!netBuf.nbflags.HasRouted)
  452.   return;
  453.   for (rover = 0; rover <= netBuf.nbHiRouteInd; rover++)
  454.     {
  455.     sPrintf(temp, "R%d.%d", thisNet, rover);
  456.     makeSysName(fn, temp, &cfg.netArea);
  457.     if ((netMisc = safeopen(fn, READ_ANY)) != NULL)
  458.       {
  459.       getMsgStr(getNetChar, temp, NAMESIZE);
  460.       getMsgStr(getNetChar, temp, NAMESIZE);
  461.       StartDecode(ReadRoutedDest);
  462.       RCount = SCount = 0;
  463.       while (getMessage(ReadRouted, TRUE, TRUE, TRUE))
  464.         {
  465.         strCpy(msgBuf.mbroom, "Mail");
  466.         NetFormat();
  467.  
  468.         }
  469.       fclose(netMisc);
  470.       unlink(fn);
  471.  
  472.       }
  473.  
  474.     }
  475.   netBuf.nbflags.HasRouted = FALSE;
  476.   netBuf.nbHiRouteInd        = 0;
  477.  
  478.   }
  479. /*
  480. * ReadRoutedDest()
  481. *
  482. * A work function to read encrypted data.
  483. */
  484. int ReadRoutedDest(int c)
  485.   {
  486.   RWorkBuf[RCount++] = c;
  487.   return TRUE;
  488.  
  489.   }
  490. /*
  491. * ReadRouted()
  492. *
  493. * This function will read a routed char for getMessage().
  494. */
  495. int ReadRouted()
  496.   {
  497.   int c;
  498.   if (RCount != SCount)
  499.   return RWorkBuf[SCount++];
  500.   RCount = SCount = 0;
  501.   while (SCount == RCount && (c = fgetc(netMisc)) != EOF)
  502.   Decode(c);
  503.   if (RCount != SCount)
  504.   return RWorkBuf[SCount++];
  505.   if (c == EOF) StopDecode();
  506.   if (RCount != SCount)
  507.   return RWorkBuf[SCount++];
  508.   return -1;
  509.  
  510.   }
  511. /*
  512. * getNetChar()
  513. *
  514. * This function gets a character from a network temporary file.
  515. */
  516. int getNetChar()
  517.   {
  518.   int c;
  519.   c = fgetc(netMisc);
  520.   if (c == EOF) return -1;
  521.   return c;
  522.  
  523.   }
  524. #define WeServe(x)      SearchList(&Serves, x)
  525. /*
  526. * LocalName()
  527. *
  528. * This takes a string of form <system> _ <domain> and attempts to discover if
  529. * this domain mapped system is actually a local.  This is used when we're
  530. * sending mail and are trying to find out if a Who Else override needs to be
  531. * generated.  Ugly kludge, but, hey, that's what programming's all about, eh?
  532. */
  533. char *LocalName(char *system)
  534.   {
  535.   char *domain, *System;
  536.   if ((domain = strchr(system, '_')) == NULL) return system;
  537.   domain += 2;  /* always preceded by a space -- or so we assume */
  538.   if (strCmpU(domain, cfg.codeBuf + cfg.nodeDomain) == SAMESTRING ||
  539.   WeServe(domain) != NULL)
  540.     {
  541.     System = strdup(system);
  542.     if ((domain = strchr(System, ' ')) == NULL)
  543.     return system;      /* should never happen, though */
  544.     *domain = NULL;
  545.     if (searchNameNet(System, &netTemp) != ERROR)
  546.       {
  547.       free(System);
  548.       return netTemp.netName;
  549.  
  550.       }
  551.     free(System);
  552.  
  553.     }
  554.   return system;
  555.  
  556.   }
  557. /*
  558. * SepNameSystem()
  559. *
  560. * This will parse an Other Recipient spec.
  561. */
  562. char SepNameSystem(char *string, char *person, char *system, NetBuffer *buf)
  563.   {
  564.   char  *c;
  565.   label domain;
  566.   char dup, work[150];          /* should be sufficient */
  567.   int   slot;
  568.   strCpy(work, string);
  569.   if ((c = strchr(work, '@')) == NULL)
  570.     {
  571.     if (strLen(work) >= NAMESIZE) return BAD_FORMAT;
  572.     strCpy(person, string);
  573.     return NOT_SYSTEM;
  574.  
  575.     }
  576.   *c++ = 0;
  577.   NormStr(work);
  578.   NormStr(c);
  579.   if (strLen(c) >= NAMESIZE * 2 || strLen(work) >= NAMESIZE)
  580.   return BAD_FORMAT;
  581.   strCpy(system, c);
  582.   strCpy(person, work);
  583.   if (buf == NULL) return IS_SYSTEM;    /* very minor cheat - see CTDL.C */
  584.   if ((slot = searchNameNet(c, buf)) != ERROR)
  585.     {
  586.     /* try secondary lists */
  587.     strCpy(system, buf->netName);       /* get "real" name */
  588.     if (buf->nbflags.local)
  589.       {
  590.       return IS_SYSTEM;
  591.  
  592.       }
  593.  
  594.     }
  595.   if (SystemInSecondary(c, domain, &dup))
  596.     {
  597.     if (dup)
  598.       {
  599.       /* oops */
  600.       return (char) (slot == ERROR) ? NO_SYSTEM : IS_SYSTEM;
  601.  
  602.       }
  603.     if (strCmpU(domain, cfg.nodeDomain + cfg.codeBuf) == SAMESTRING &&
  604.     (strCmpU(c, cfg.nodeName + cfg.codeBuf) == SAMESTRING ||
  605.     strCmpU(c, UseNetAlias(cfg.nodeName+cfg.codeBuf, TRUE))
  606.     == SAMESTRING))
  607.       {
  608.       printf("Hey, that's this system!\n ");
  609.       return SYSTEM_IS_US;
  610.  
  611.       }
  612.     sPrintf(system, "%s _ %s", c, domain);
  613.     return IS_SYSTEM;
  614.  
  615.     }
  616.   return (char) (slot == ERROR) ? NO_SYSTEM : IS_SYSTEM;
  617.  
  618.   }
  619. static label SearchResult;
  620. static char  *SearchTarget, GetAlias;
  621. /*
  622. * UseNetAlias()
  623. *
  624. * This will find a usenet alias or the converse.
  625. */
  626. char *UseNetAlias(char *Name, char FindAlias)
  627.   {
  628.   void *EatTrans();
  629.   SListBase Dummy =
  630.     {
  631.     NULL, NULL, NULL, NULL, EatTrans
  632.  
  633.     };
  634.   SYS_FILE fn;
  635.   char *c, *WorkName;
  636.   WorkName = strdup(Name);      /* use a work buffer */
  637.   SearchResult[0] = 0;
  638.   SearchTarget = WorkName;
  639.   if (!FindAlias) while ((c = strchr(WorkName, ' ')) != NULL) *c = '_';
  640.   makeSysName(fn, "aliases.sys", &cfg.roomArea);
  641.   GetAlias = FindAlias;
  642.   MakeList(&Dummy, fn, NULL);   /* CHEAT!  WHEEEEEE! */
  643.   free(WorkName);
  644.   if (strLen(SearchResult) == 0) return Name;
  645.   if (FindAlias) while ((c = strchr(SearchResult, '_')) != NULL) *c = ' ';
  646.   return SearchResult;
  647.  
  648.   }
  649. /*
  650. * EatTrans()
  651. *
  652. * This will eat a line of input for alias processing.
  653. */
  654. void *EatTrans(char *line)
  655.   {
  656.   char *c;
  657.   if ((c = strchr(line, ' ')) != NULL)
  658.     {
  659.     *c = 0;
  660.     if (GetAlias)
  661.       {
  662.       /* check second field */
  663.       if (strCmpU(c + 1, SearchTarget) == SAMESTRING)
  664.         {
  665.         strCpy(SearchResult, line);
  666.  
  667.         }
  668.  
  669.       }
  670.     else
  671.       {
  672.       /* check first field */
  673.       if (strCmpU(line, SearchTarget) == SAMESTRING)
  674.         {
  675.         strCpy(SearchResult, c + 1);
  676.  
  677.         }
  678.  
  679.       }
  680.  
  681.     }
  682.   return NULL;
  683.  
  684.   }
  685. /*
  686. * SearchSecondary()
  687. *
  688. * This searches a secondary (domain) list for a system.
  689. */
  690. static char SearchSecondary(char *secondary,char *Name,char *Domain,char *isdup)
  691.   {
  692.   FILE *fd;
  693.   int  bucket;
  694.   char found, *tab, *c, *tab2;
  695.   char line[90];
  696.   JumpInfo JumpTable[BUCKETCOUNT];
  697.   if ((fd = fopen(secondary, READ_ANY)) == NULL)
  698.   return FALSE;
  699.   fread(line, VERS_SIZE + 1, 1, fd);
  700.   fread(JumpTable, sizeof JumpTable, 1, fd);
  701.   #ifdef IS_MOTOROLA
  702.   for (bucket = 0; bucket < BUCKETCOUNT; bucket++)
  703.   Intel32ToMotorola(&JumpTable[bucket].offset);
  704.   #endif
  705.   bucket = (isdigit(Name[0])) ? Name[0] - '0' :
  706.   toUpper(Name[0]) - 'A' + 10;
  707.   fseek(fd, JumpTable[bucket].offset, 0);
  708.   found = FALSE;
  709.   do
  710.     {
  711.     *isdup = FALSE;
  712.     if (fgets(line, sizeof line, fd) == NULL) break;
  713.     if ((tab2 = strchr(line, '\n')) != NULL)
  714.     *tab2 = 0;
  715.     if (strlen(line) == 0)
  716.       {
  717.       break;
  718.  
  719.       }
  720.     if (line[0] <= ' ')
  721.       {
  722.       switch (line[0])
  723.         {
  724.         case DUP:
  725.         *isdup = TRUE;
  726.         break;
  727.         default: printf("Ooop!");
  728.         break;
  729.  
  730.         }
  731.       c = line + 1;
  732.  
  733.       }
  734.     else c = line;
  735.     tab = strchr(c, '\t');
  736.     *tab++ = 0;
  737.     if (strCmpU(c, Name) == 0)
  738.     found = TRUE;
  739.     if (strCmpU(c, Name) > 0) break;
  740.  
  741.     }
  742.   while (!found);
  743.   if (found)
  744.     {
  745.     if ((tab2 = strchr(tab, '\t')) != NULL)
  746.     *tab2++ = 0;
  747.     strCpy(Domain, tab);
  748.     if (tab2 != NULL)    /* alias?  Copy it into search string */
  749.     strCpy(Name, tab2);
  750.  
  751.     }
  752.   fclose(fd);
  753.   return found;
  754.  
  755.   }
  756. /*
  757. * SystemInSecondary()
  758. *
  759. * This will look for a system in secondary lists.
  760. */
  761. char SystemInSecondary(char *Name, char *Domain, char *dup)
  762.   {
  763.   int rover;
  764.   char *sep;
  765.   SYS_FILE secondary;
  766.   label name;
  767.   char WorkName[(NAMESIZE * 2) + 1];
  768.   char SearchSecondary(char *secondary,char *Name,char *Domain,char *isdup);
  769.   strCpy(WorkName, Name);
  770.   /* is the domain specified already?  if so, parse it */
  771.   if ((sep = strchr(WorkName, '_')) != NULL ||
  772.   (sep = strchr(WorkName, '.')) != NULL)
  773.     {
  774.     *sep++ = 0;
  775.     NormStr(WorkName);
  776.     NormStr(sep);
  777.     if (strchr(sep, '_') != NULL ||
  778.     strchr(sep, '.') != NULL)
  779.     return FALSE;       /* no subdomains */
  780.     strCpy(Name, WorkName);
  781.     strCpy(Domain, sep);
  782.     *dup = FALSE;               /* by definition */
  783.     return TRUE;
  784.  
  785.     }
  786.   Domain[0] = 0;
  787.   for (rover = 0; rover < 100; rover++)
  788.     {
  789.     sPrintf(name, "nodes%d.fst", rover);
  790.     makeSysName(secondary, name, &cfg.netArea);
  791.     if (access(secondary, 0) != 0) break;
  792.     if (SearchSecondary(secondary, Name, Domain, dup)) break;
  793.  
  794.     }
  795.   strCpy(WorkName, Name);
  796.   /* make sure we found something and it's not us */
  797.   return (Domain[0] != 0 &&
  798.   strCmpU(Name, cfg.codeBuf + cfg.nodeName) != SAMESTRING &&
  799.   strCmpU(UseNetAlias(WorkName,FALSE), cfg.codeBuf + cfg.nodeName)
  800.   != SAMESTRING);
  801.  
  802.   }
  803. extern VirtualRoom *VRoomTab;
  804. extern VirtNet     *VirtNetList;
  805. extern char VirtualInUse;
  806. extern int  VirtSize, VNetSize;
  807. /*
  808. * MODoVirtuals()
  809. *
  810. * This sends rooms to another system, if needed.
  811. */
  812. void MODoVirtuals()
  813.   {
  814.   int rover, which, x;
  815.   if (!VirtualInUse) return ;
  816.   for (rover = 0; rover < VIRT_LIMIT; rover++)
  817.     {
  818.     x = VirtNetList[thisNet].VirtList[rover].WhichVirt;
  819.     if (x >= VirtSize || x < 0 || !VRoomInuse(x))
  820.     VirtNetList[thisNet].VirtList[rover].WhichVirt = -1;
  821.     if (VirtNetList[thisNet].VirtList[rover].WhichVirt != -1)
  822.       {
  823.       SendVirtual(rover, NULL, NULL, NULL);
  824.  
  825.       }
  826.  
  827.     }
  828.  
  829.   }
  830. /*
  831. * SendVirtual()
  832. *
  833. * This manages sending a room to another system.
  834. */
  835. int SendVirtual(int VirtIndex, char *d1, char *d2, char *d3)
  836.   {
  837.   int   VirtNo, count;
  838.   MSG_NUMBER StartMsg;
  839.   VirtNo = VirtNetList[thisNet].VirtList[VirtIndex].WhichVirt;
  840.   /* Send all the new LD messages received */
  841.   StartMsg = VirtNetList[thisNet].VirtList[VirtIndex].LDSent;
  842.   count = ThrowAll(VirtNo, LD_DIR, StartMsg, VRoomTab[VirtNo].vrHiLD,
  843.   VRoomTab[VirtNo].vrName);
  844.   VirtNetList[thisNet].VirtList[VirtIndex].LDSent =
  845.   VRoomTab[VirtNo].vrHiLD;
  846.   if (VirtNetList[thisNet].VirtList[VirtIndex].mode != PEON)
  847.     {
  848.     StartMsg = VirtNetList[thisNet].VirtList[VirtIndex].LocSent;
  849.     count += ThrowAll(VirtNo, LOCAL_DIR, StartMsg,
  850.     VRoomTab[VirtNo].vrHiLocal, VRoomTab[VirtNo].vrName);
  851.     VirtNetList[thisNet].VirtList[VirtIndex].LocSent =
  852.     VRoomTab[VirtNo].vrHiLocal;
  853.  
  854.     }
  855.   VRoomTab[VirtNo].vrChanged |= SENT_DATA;
  856.   return count;
  857.  
  858.   }
  859. /*
  860. * ThrowAll()
  861. *
  862. * This sends a virtual room to another system.
  863. */
  864. static int ThrowAll(int which, char *distance, MSG_NUMBER start, MSG_NUMBER end,
  865. char *room)
  866.   {
  867.   MSG_NUMBER  rover;
  868.   int           count=0;
  869.   char  fn[100];
  870.   extern char *READ_ANY;
  871.   extern PROTO_TABLE Table[];
  872.   extern int    TransProtocol;
  873.   for (rover = start + 1; rover <= end; rover++)
  874.     {
  875.     CreateVAName(fn, which, distance, rover);
  876.     if ((netMisc = safeopen(fn, READ_ANY)) != NULL)
  877.       {
  878.       while (getMessage(getNetChar, TRUE, TRUE, TRUE))
  879.         {
  880.         count++;
  881.         strCpy(msgBuf.mbroom, room);
  882.         NetFormat();
  883.  
  884.         }
  885.       fclose(netMisc);
  886.  
  887.       }
  888.  
  889.     }
  890.   return count;
  891.  
  892.   }
  893. void Intel32ToMotorola(UNS_32 *val)
  894.   {
  895.   unsigned long temp;
  896.   temp = *val;
  897.   *val = ((ULONG)(temp & 0xff) << 24) + ((ULONG)(temp & 0xff00) << 8) +
  898.   ((ULONG)(temp & 0xff0000) >> 8) + ((ULONG)(temp &0xff000000) >> 24);
  899.  
  900.   }
  901.